#pragma once
#include "Pascal.h"

template <class Integer>
class TFPGIntegers : public TFPGList<Integer> {};

	#ifndef TDataTable_H
	#define TDataTable_H
	template <typename T>
	class TDataTableEnumerator_2;
	//template <typename T>
	//struct TDataSlot_2;
	template <typename T>
	class TDataTable
	{
	public:
		//template <typename T>
		struct TDataSlot
		{
		public:
			T Value;
			Boolean Used;

			TDataSlot()
			{
			};
		};
		

		class TDataTableEnumerator;
		/*class TDataTableEnumerator
		{
		public:
			T GetCurrent();
			Boolean MoveNext();
			procedure Reset();
		public:
			//property Current: T read GetCurrent;
		public:
			TDataTable FTable;
			Integer FCurrentIndex;
		public:
			TDataTableEnumerator(TDataTable ATable);
		};*/
	public:
		typedef TDataSlot FSlots_Type;
	public:
		FSlots_Type* FSlots;
		TFPGIntegers<Integer> FUsedSlots;
	public:
		procedure SetValue(Integer AIndex, T &AValue);
		T GetValue(Integer AIndex);
		Integer GetSize();
		procedure SetSize(Integer ASize);
		T GetUsedValue(Integer AIndex);
		Integer GetUsedValuesCount();
	public:
		//property UsedValues[AIndex: Integer]: T read GetUsedValue;
		//property UsedValuesCount: Integer read GetUsedValuesCount;
		//property Values[AIndex: Integer]: T read GetValue write SetValue; default;
		//property Size: Integer read GetSize write SetSize;
	public:
		TDataTable();
		~TDataTable();
		procedure Clear();
		Boolean GetValue2(Integer AIndex, T &AValue);
		TDataTableEnumerator_2<T> GetEnumerator();
	};
	#endif
	
		/*template <typename T>
		struct TDataTable<T>::TDataSlot : public TDataTable<T>
		{
			T Value;
			Boolean Used;
		};*/

		//template <typename T>
		//struct TDataSlot_2 : public TDataTable<T>::TDataSlot {};
	
		template <typename T>
		class TDataTable<T>::TDataTableEnumerator : public TDataTable<T>
		{
		public:
			T GetCurrent();
			Boolean MoveNext();
			procedure Reset();
		public:
			//property Current: T read GetCurrent;
		public:
			TDataTable FTable;
			Integer FCurrentIndex;
		public:
			TDataTableEnumerator(TDataTable ATable);
		};

		
		template <typename T>
		class TDataTableEnumerator_2 : public TDataTable<T>::TDataTableEnumerator {};

	template <typename T>
	class TDataTableManager
	{
	public:
		typedef TDataTable<T> TTable;
	private:
		Integer FTableSize;
	public:
		TDataTable<T> CreateInstance();
		procedure ClearInstance(TTable AInstance);
		procedure DestroyInstance(TTable AInstance);
	public:
		TDataTableManager(Integer ATableSize);
		~TDataTableManager();
	};
